//
//  ChartView.m
//  SaveMoney
//
//  Created by Jose Sánchez Martínez on 11/11/11.
//  Copyright (c) 2011 Mubiquo. All rights reserved.
//

#import "ChartView.h"

@implementation ChartView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
    }
    return self;
}

#define offset 10
#define barnumber 12

- (void)drawRect:(CGRect)rect {
    
    NSArray *values = [NSArray arrayWithObjects:[NSNumber numberWithFloat:.5], [NSNumber numberWithFloat:.9],[NSNumber numberWithFloat:.4], nil];
    
    CGFloat height = self.bounds.size.height;
    CGFloat width = self.bounds.size.width;
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);
    CGContextSetFillColorWithColor(context, [UIColor grayColor].CGColor);
    CGFloat barWidth = (width - 2*offset)/barnumber;
    int count = 0;
    for (NSNumber *num in values) {
        CGFloat x = count * (barWidth + 10) + offset;
        CGRect barRect = CGRectMake(x, height/2 - [num floatValue] * height/2, barWidth, [num floatValue] * height/2);
        CGContextAddRect(context, barRect);
        count++;
    }
    CGContextFillPath(context);
}

@end
